package xyz.xiezc.mzix.common.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static xyz.xiezc.mzix.common.dto.WebResponseCode.OK;

@AllArgsConstructor
@Data
public class WebResponse {

  WebResponseCode code;
  String message;

  Map<String, Object> result;

  public void put(String key, Object value) {
    if (result == null) {
      result = new HashMap<>();
    }
    result.put(key, value);
  }

  public static WebResponse fail(WebResponseCode code, String message) {
    return new WebResponse(code, message, new HashMap<>());
  }

  public static WebResponse success(String key, Object value) {
    WebResponse webResponse = new WebResponse(OK, "", new HashMap<>());
    webResponse.getResult().put(key, value);
    return webResponse;
  }

  public static WebResponse success() {
    return new WebResponse(OK, "", new HashMap<>());
  }





}
